﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace PRET.ReportControlLib.Controls
{
    public partial class VoltageTimePanel : UserControl
    {
        public event ShowVoltageReportViewEventHandle showReportEvent;
        public DateTime getStartTime
        {
            get
            {
                return this.startTimePicker.Value.Date;
            }
        }

        public DateTime getEndTime
        {
            get
            {
                return this.endTimePicker.Value.Date.AddDays(1);
            }
        }

        public void EnableControls(bool sign)
        {
            this.startTimePicker.Enabled = sign;
            this.endTimePicker.Enabled = sign;
            this.reportViewBtn.Enabled = sign;
        }

        public VoltageTimePanel()
        {
            InitializeComponent(); 
            string startYear = string.Format("{0}/{1}/01", DateTime.Now.Year, DateTime.Now.Month);
            this.startTimePicker.Value = DateTime.Parse(startYear);
            this.endTimePicker.Value = DateTime.Today;
        }

        private void SetMeterTimePanel_Load(object sender, EventArgs e)
        {
            this.endTimePicker.MinDate = this.startTimePicker.Value;
            this.endTimePicker.MaxDate = DateTime.Now;
            this.startTimePicker.MaxDate = this.endTimePicker.Value;
        }

        private void startTimePicker_ValueChanged(object sender, EventArgs e)
        {
            this.endTimePicker.MinDate = this.startTimePicker.Value;
        }

        private void endTimePicker_ValueChanged(object sender, EventArgs e)
        {
            this.startTimePicker.MaxDate = this.endTimePicker.Value;
        }

        private void reportViewBtn_Click(object sender, EventArgs e)
        {
            if (showReportEvent != null)
            {
                ShowVoleageReportViewEventArgs eventArg = new ShowVoleageReportViewEventArgs();
                eventArg.StartTime = this.getStartTime;
                eventArg.EndTime = this.getEndTime;
                showReportEvent(this, eventArg);
            }
        }
    }

    public delegate void ShowVoltageReportViewEventHandle(object sender, ShowVoleageReportViewEventArgs args);

    public class ShowVoleageReportViewEventArgs : EventArgs
    {
        public ShowVoleageReportViewEventArgs()
        { }
        private DateTime startTime;
        private DateTime endTime;

        public DateTime StartTime
        {
            get { return startTime; }
            set { startTime = value; }
        }
        public DateTime EndTime
        {
            get { return endTime; }
            set { endTime = value; }
        }
    }
}
